import {messages} from 'share/common';
/**
 * Created by ke.ouyang on 19/10/29
 * Email ke.ouyang@huilianyi.com
 */
import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
import configureStore from 'stores';

export default {
  //获取是否是老公司信息
  getIsOldCompanyValue() {
    return configureStore.store.getState().login.isOldCompany;
  },
  //获取老公司人员信息
  getOldCompanyPersonPositionInfo(positionInfo) {
    if (positionInfo && positionInfo.length) {
      return positionInfo.map(item => {
        item.companyId = item.legalEntityId;
        item.companyName = item.legalEntityName;
        return item;
      });
    } else {
      return positionInfo;
    }
  },
  //获取个人基本信息
  getPersonDetail(userOID) {
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/users/v2/' + userOID)
        .then((res) => {
          if (this.getIsOldCompanyValue()) {
            res.data.userJobsDTOs = this.getOldCompanyPersonPositionInfo(res.data.userJobsDTOs);
          }
          resolve(res);
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        });
    });
  },
  //获取配置列表
  getSetList() {
    return httpFetch.get(`${config.baseUrl}/api/userFieldSetting/search`);
  },
  //更新配置列表
  updateSetList(params) {
    return httpFetch.put(`${config.baseUrl}/api/userFieldSetting/update`, params);
  },

};
